package com.starsoft.quant.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.starsoft.frame.core.orm.BaseDao;
import com.starsoft.quant.bean.QuantModelParam;
import com.starsoft.quant.bean.QuantModelParamData;

@Repository
public class ModelParamDao extends BaseDao<QuantModelParam, Integer>{
	
	public static Logger logger = LoggerFactory.getLogger(ModelParamDao.class);
	
	public List<QuantModelParam> getModelParam(String modelCode){
		Map<String,Object> params = new HashMap<>();
		params.put("modelCode", modelCode);
		return this.findByMap(params);
	}

	public List<QuantModelParamData> getModelParamData(Integer acountId){
		Map<String, Object> params = new HashMap<>();
		params.put("acountId", acountId);
		return this.findByMap(QuantModelParamData.class, params);
	}
	
	public void deletePamamData(QuantModelParamData modelParamData){
		this.delete(modelParamData);
	}

	public void saveParamData(QuantModelParamData paramData) {
		Map<String, Object> params = new HashMap<>();
		params.put("acountId", paramData.getAcountId());
		params.put("paramId", paramData.getParamId());
		QuantModelParamData paramDataOld = this.getByMap(QuantModelParamData.class, params);
		if(paramDataOld!=null){
			paramDataOld.setValue(paramData.getValue());
			this.saveOrUpdate(paramDataOld);
		}else{
			this.saveOrUpdate(paramData);
		}
	}
	
}
